﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;

namespace FYPHP
{
    public partial class SiteMaster : System.Web.UI.MasterPage
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["fyphp"].ConnectionString);

        protected void Page_Load(object sender, EventArgs e)
        {
            var control = Page.LoadControl("~/leftColumn.ascx");
            PlaceHolder1.Controls.Add(control);

            SqlCommand cmdSearch;
            SqlDataReader dtrSearch;
            conn.Open();

            cmdSearch = new SqlCommand("Select a_link, a_picture From Advertisements Where a_status='published'", conn);
            dtrSearch = cmdSearch.ExecuteReader();

            ItemList.DataSource = dtrSearch;
            ItemList.DataBind();

            dtrSearch.Close();
            conn.Close();
            
          
            if (Session["ID"]==null)
            {
                //<asp:Label ID="Label1" runat="server" Text="Label">Log in</asp:Label>
                //   <a href="~/SignIn.aspx" runat="server">Log In</a> 

                Label1.Text = "[ <a href='http://localhost:34874/SignIn.aspx' runat='server'>Log In</a> ]";
                
            }
            else 
            {
                Label1.Text = "[ <a href='http://localhost:34874/SignOut.aspx' runat='server'>Log Out</a> ]";

            }
            

        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            Session["searchText"] = txtSearch.Text;
            Response.Redirect("SearchResult.aspx");
        }

        private void MessageBox(string msg)
        {
            Label lbl = new Label();
            lbl.Text = "<script language='javascript'>" + Environment.NewLine + "window.alert('" + msg + "')</script>";
            Page.Controls.Add(lbl);
        }
    }
}
